<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body,
      ul {
        margin: 0;
        padding: 0;
      }
      body {
        width: 100%;
        height: 100%;
        background-image: url(../../images/grid.png);
      }
      svg {
        background-color: rgba(255, 0, 0, 0.1);
      }
    </style>
  </head>
  <body>
    <svg id="hySvg" width="300" height="300">
      <rect id="rectangle1" x="0" y="0" width="100" height="50"></rect>
    </svg>

    <script src="./libs/snap.svg-min.js"></script>
    <script>
      window.onload = function () {
        let svg = Snap('#hySvg')
        let paper = svg.paper

        // 1.绘制一个矩形
        let rectangle = paper.rect(0, 100, 100, 50)
        rectangle.attr({
          fill: 'red',
        })

        // 2.选择一个矩形
        let rectangle1 = paper.select('#rectangle1')
        rectangle1.attr({
          fill: 'green',
        })

        // 3.动画的实现（requestAnimationFrame 1s 60次）
        Snap.animate(
          [0, 0], // from(可以是数组会数字)
          [200, 200], // to
          function (val) {
            console.log('val', val)
            rectangle1.attr({
              x: val[0],
              y: val[1],
            })
          },
          1000, // 毫秒
          mina.linear,
          function () {
            console.log('动画结束了')
          }
        )
      }
    </script>
  </body>
</html>
